import { CHANGE_BANNER }  from "./constants"
import axios from "axios"

const changeBannersAction = (banner) => ({
  // type: "change_Banner",
  type: CHANGE_BANNER,
  banner
})
  
// 调用 fetchNetWorkDataAction 不在返回一个action对象，而是一个action函数
const fetchNetWorkDataAction = () => {

  // foo 函数就是要被派发出去的函数，派发后他会自动执行
  function foo(dispatch, getState){
    axios.get("http://123.207.32.32:8000/home/multidata").then(res => {
      const banners = res.data.data.banner.list
      // 网络请求成功后，通过dispatch派发一个action对象，给store赋值
      dispatch(changeBannersAction(banners))
    })
  }

  return foo
}

export { changeBannersAction, fetchNetWorkDataAction }